﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Windows.Input;
using System.Windows.Threading;

namespace FLHook.Manager.Sockets
{
    public class FLHookClient : DispatcherObject, IDisposable, INotifyPropertyChanged
    {
        private volatile bool _isBusy;
        private volatile bool _disposed;
        private readonly IPEndPoint _localEP;
        private readonly TcpClient _tcpClient;
        private readonly string _authenticationKey;

        public FLHookClient(IPEndPoint localEP, string authenticationKey)
        {
            _localEP = localEP;
            _authenticationKey = authenticationKey;
            _tcpClient = new TcpClient();
        }

        public bool Connected
        {
            get { return _tcpClient.Connected; }
        }

        public bool IsBusy
        {
            get { return _isBusy; }
        }

        public void Close()
        {

        }

        public void Connect()
        {

        }

        #region IDisposable

        ~FLHookClient()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected void Dispose(bool disposing)
        {
            if (_disposed)
                return;
            if (disposing)
            {
                _tcpClient.Close();
            }
            _disposed = true;
        }

        #endregion

        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler == null)
                return;
            if (CheckAccess())
                handler(this, new PropertyChangedEventArgs(propertyName));
            else
                Dispatcher.BeginInvoke(new Action<string>(RaisePropertyChanged), propertyName);
        }

        #endregion

    }

    public abstract class FLCommand
    {
        public abstract string Command { get; }

        public bool CanExecute()
        {
            

            throw new NotImplementedException();
        }

        public bool Execute()
        {
            throw new NotImplementedException();
        }

    }

}
